package tt.dz.order.pojo;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import tt.dz.order.dao.BaseDAOUtil;

/**
 * @Title 有贝先付支付回调记录
 * @author zhoutian   
 * @date 2015-11-26
 */
public class YouBeiPayCallBackRecord {
	//商户系统唯一订单号
	private String orderNo;
	//签名方式,固定取值为RSA
	private String signType;
	//签名,用于验证回调请求参数是否被篡改过
	private String sign;
	//商户订单时间，作为买家付款时间
	private String gmtPayment;
	//有贝先付支付单号
	private String tradeNo;
	//交易状态码
	private String tradeStatus;
	//商户编号，商户（电桩）在有贝先付支付平台上开设的商户号码，为18位数字
	private String partnerNo;
	//交易金额
	private BigDecimal totalFee;
	//清算日期
	private String settleDate;
	//商品描述,该笔订单的备注、描述、明细等。对应请求时的body参数，原样通知回来
	private String orderDesc;
	//创建时间
	private Date createTime;

	public String getOrderNo() {
		return orderNo;
	}

	public void setOrderNo(String orderNo) {
		this.orderNo = orderNo;
	}

	public String getSignType() {
		return signType;
	}

	public void setSignType(String signType) {
		this.signType = signType;
	}

	public String getSign() {
		return sign;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}

	public String getGmtPayment() {
		return gmtPayment;
	}

	public void setGmtPayment(String gmtPayment) {
		this.gmtPayment = gmtPayment;
	}

	public String getTradeNo() {
		return tradeNo;
	}

	public void setTradeNo(String tradeNo) {
		this.tradeNo = tradeNo;
	}

	public String getTradeStatus() {
		return tradeStatus;
	}

	public void setTradeStatus(String tradeStatus) {
		this.tradeStatus = tradeStatus;
	}

	public String getPartnerNo() {
		return partnerNo;
	}

	public void setPartnerNo(String partnerNo) {
		this.partnerNo = partnerNo;
	}

	public BigDecimal getTotalFee() {
		return totalFee;
	}

	public void setTotalFee(BigDecimal totalFee) {
		this.totalFee = totalFee;
	}

	public String getSettleDate() {
		return settleDate;
	}

	public void setSettleDate(String settleDate) {
		this.settleDate = settleDate;
	}

	public String getOrderDesc() {
		return orderDesc;
	}

	public void setOrderDesc(String orderDesc) {
		this.orderDesc = orderDesc;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public YouBeiPayCallBackRecord() {
		this.createTime = new Date();
	}
	
	public YouBeiPayCallBackRecord(Map<String, String> params) {
		this.orderNo = params.get("no_order");
		this.signType = params.get("sign_type");
		this.sign = params.get("sign");
		this.gmtPayment = params.get("dt_order");
		this.tradeNo = params.get("oid_paybill");
		this.tradeStatus = params.get("result_pay");
		this.partnerNo = params.get("oid_partner");
		this.totalFee = new BigDecimal(params.get("money_order"));
		this.settleDate = params.get("settle_date");
		this.orderDesc = params.get("info_order");
		this.createTime = new Date();
	}
	
	public void save(){
		String sql = "insert into order_youbeipay_callback_record(orderNo, signType, sign, gmtPayment, tradeNo, tradeStatus, partnerNo, totalFee,  orderDesc, createTime) values(:orderNo, :signType, :sign, :gmtPayment, :tradeNo, :tradeStatus, :partnerNo, :totalFee,  :orderDesc, :createTime)";
		BaseDAOUtil.updateObject(sql, this);
	}
	
	public void update(){
		String sql = "update order_youbeipay_callback_record set orderNo = :orderNo, signType = :signType, sign = :sign, gmtPayment = :gmtPayment, tradeNo = :tradeNo, tradeStatus = :tradeStatus, partnerNo = :partnerNo, totalFee = :totalFee,  orderDesc = :orderDesc, createTime = :createTime where orderNo = :orderNo";
		BaseDAOUtil.updateObject(sql, this);
	}
	
	public static YouBeiPayCallBackRecord getBy(String orderNo){
		String sql = "select orderNo, signType, sign, gmtPayment, tradeNo, tradeStatus, partnerNo, totalFee,  orderDesc, createTime from order_youbeipay_callback_record where orderNo = :orderNo";
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("orderNo", orderNo);
		return BaseDAOUtil.queryForObject(sql, paramMap, YouBeiPayCallBackRecord.class);
	}
	
	/**
	 * 根据多个订单号查询充电预约订单支付回调记录
	 * @param orderIds 订单号(多个)
	 * @return 充电预约订单支付回调记录
	 */
	public static List<YouBeiPayCallBackRecord> getByIds(List<String> orderNos){
		String sql = "select orderNo, signType, sign, gmtPayment, tradeNo, tradeStatus, partnerNo, totalFee,  orderDesc, createTime from order_youbeipay_callback_record where orderNo in (:orderNos)";
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("orderNos", orderNos);
		return BaseDAOUtil.queryForList(sql, paramMap, YouBeiPayCallBackRecord.class);
	}
}
